<template>
	<view class="page-height">
		<i-top-bar title="温馨提示"> </i-top-bar>
		<view class="page-content">
			<view class="html-view">
				<u-parse :content="formatRichText(content)"></u-parse>
			</view>

			<view class="btn-view">
				<text class="btn-text center btn-text-confirm" v-if="time > 0">我已知悉({{time}}S)</text>
				<text class="btn-text center btn-text-confirm" @click="confirm" v-else>我已知悉</text>
			</view>

		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				content: "",
				time: 3,
				timer: null,
			};
		},

		onLoad() {
			this.getData()
			this.startTimer()
		},
		onUnload() {
			clearInterval(this.timer)
		},

		methods: {
			startTimer() {
				clearInterval(this.timer)
				this.timer = setInterval(() => {
					if (this.time > 0) {
						this.time--
					} else {
						this.time = 0
						clearInterval(this.timer)
					}
				}, 1000)
			},
			getData() {
				this.api.post('/api/work/getNotice').then(async (res) => {
					this.content = res.notice
				}).catch(err => {
					this.apiErr(err)
				}).finally(() => {
					this.loadingHide();
				})
			},
			confirm() {
				uni.redirectTo({
					url: '/pages/order/add-order'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page-height {
		background: #ffffff;
	}

	.page-content {
		display: flex;
		flex-direction: column;
		position: relative;
		z-index: 1;
		padding: 30rpx 30rpx 30rpx;
	}

	.html-view {
		padding: 0rpx 10rpx;
		color: #333333;
		font-size: 26rpx;
		line-height: 46rpx;

		p {
			font-size: 26rpx;
		}
	}

	.btn-view {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 50rpx 0 30rpx;

		.btn-text {
			color: #55C29A;
			font-size: 28rpx;
			height: 76rpx;
			line-height: 76rpx;
			width: 100%;
			border-radius: 100px;
			border: 1px solid #55C29A;
		}

		.btn-text-confirm {
			color: #ffffff;
			border: 1px solid #55C29A;
			background-color: #55C29A;
		}

	}
</style>